<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="/static/admin/lib/jq-module/zyupload/zyupload-1.0.0.min.css" media="all">
    <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
    <link rel="stylesheet" href="/static/kindeditor/themes/default/default.css" />
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form">
            <div class="layui-form-item">
                 <label class="layui-form-label">帖子标题</label>
                 <div class="layui-input-block">
                     <input type="text" name="inv_title" lay-verify="required" autocomplete="off" class="layui-input" value="{$info.inv_title}">
                 </div>
           </div>

            <div class="layui-form-item">
                <label class="layui-form-label">所属板块</label>
                <div class="layui-input-inline">
                    <select name="plate_id" lay-verify="required" lay-search="">
                        {if !empty($plates)}
                        {volist name="$plates" id="ps"}
                        <option value="{$ps.plate_id}" {if $info.plate_id == $ps.plate_id}selected{/if} {if $ps.plate_type == 2}disabled{/if}>{$ps.plate_name}</option>
                        {/volist}
                        {/if}
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">所属行政</label>
                <div class="layui-input-inline">
                    <select name="boroughs_id" lay-verify="required" lay-search="">
                        <option value="0" {if $info.boroughs_id == 0}selected{/if} >请选择行政区</option>
                        {if !empty($bors)}
                        {volist name="$bors" id="bs"}
                        <option value="{$bs.boroughs_id}" {if $info.boroughs_id == $bs.boroughs_id}selected{/if} >{$bs.boroughs_name}</option>
                        {/volist}
                        {/if}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">帖子来源</label>
                <div class="layui-input-inline">
                    <select name="inv_type" lay-verify="required" lay-filter="type">
                        <option value="1" {if $info.inv_type == 1}selected{/if} >原创</option>
                        <option value="2" {if $info.inv_type == 2}selected{/if} >转载</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item" id="source" {if $info.inv_type == 1}style="display: none;"{/if}>
                <label class="layui-form-label">转载来源</label>
                <div class="layui-input-block">
                    <input type="text" name="source"  autocomplete="off" class="layui-input" value="{$info.source}">
                </div>
            </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">作者</label>
                    <div class="layui-input-inline">
                        <input type="text" name="author" lay-verify="required" autocomplete="off" class="layui-input" value="{$info.author}">
                    </div>
                </div>

            <div class="layui-form-item">
                <label class="layui-form-label">帖子封面图</label>
                <div class="layui-upload-drag" id="upload">
                    <i class="layui-icon"></i>
                    <p>点击上传，或将文件拖拽到此处</p>
                    {if !empty($info.head)}
                    <div class="layui-hide" id="uploadDemoView">
                        <hr>
                        <img src="{$info.head}" alt="上传成功后渲染" style="max-width: 196px">
                        <input type="hidden" name="inv_head" value="{$info.head}">
                    </div>
                    {/if}
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">帖子内容</label>
                <div class="layui-input-block">
                    <textarea name="inv_content" class="common-textarea" id="kindeditor_id" cols="30" style="width: 98%;" rows="10">{$info.inv_content}</textarea>
                </div>
            </div>
            <input type="hidden" name="inv_id" value="{$info.inv_id}">
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" type="button" lay-submit="" lay-filter="zz_edit">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script src="/static/admin/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="/static/admin/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/static/admin/lib/jq-module/zyupload/zyupload-1.0.0.min.js" charset="utf-8"></script>
<script charset="utf-8" src="/static/kindeditor/kindeditor-all.js"></script>
<script charset="utf-8" src="/static/kindeditor/lang/zh-CN.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    KindEditor.ready(function(K) {
        window.editor = K.create('#kindeditor_id',{
            uploadJson : '/back/upload/kindUploadImage',
            afterBlur: function(){this.sync();}
        });

    });
</script>
<script>

    layui.use(['form','upload'], function () {
        var form = layui.form
            , layer = layui.layer
            , $ = layui.jquery
            ,upload = layui.upload;

        // 图片上传
        upload.render({
            elem: '#upload'
            ,url: '/back/upload/uploads' //改成您自己的上传接口
            ,done: function(res){
                layer.msg('上传成功');
                layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', res.path);
                layui.$('#uploadDemoView').find('input').attr('value', res.path);
            }
        });

        // 选择来源
        form.on("select(type)",function(data){
            if(data.value == 2){
                $("#source").show();
            }else{
                $("#source").hide();
            }
        });

        //监听提交
        form.on('submit(zz_edit)', function (data) {
            data = data.field;
            // data.inv_content = editor.fullHtml();
            data.inv_content = editor.html();
            $.ajax({
                url : '/back/inv/edit',
                data :data,
                type:'POST',
                success:function(res){
                    if(res.code == 1){
                        layer.msg(res.msg,{icon:1,time:2000},function(){
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.location.reload();
                            parent.layer.close(index);
                        });
                    }else{
                        layer.msg(res.msg,{icon:2});
                    }

                }
            });
            return false;
        });



    });
</script>

</body>
</html>